/*
 * Copyright (c) 2019. Mikes. All rights reserved.
 *
 * You can contact me with sending email to bWlrZXNfMjAxMkAxNjMuY29t for more information!
 */

package com.climber.android.commonres.ui.pay

import com.climber.android.commonres.R
import com.climber.android.commonsdk.app.AppConstants
import com.climber.android.commonres.app.service.AppPayType
import com.climber.android.commonres.helper.onClick
import com.climber.android.commonres.ui.BaseMVPActivity
import com.climber.android.commonsdk.util.APIDataHelper
import io.ganguo.library.mvp.ui.mvp.IPresenter
import io.ganguo.library.mvp.ui.mvp.di.component.AppComponent
import io.ganguo.library.mvp.util.ToastHelper
import kotlinx.android.synthetic.main.com_activity_app_payment.*

/**
 * Created by Mikes at 2019-11-10 19:38
 */
open class AppPaymentActivity : BaseMVPActivity<IPresenter>() {
    private var prePayType: AppPayType? = AppPayType.WeChat

    protected val payMoney: Double by lazy {
        intent.getDoubleExtra(AppConstants.PARAM_PAY_MONEY, 0.0)
    }

    override fun setupActivityComponent(appComponent: AppComponent) {
    }

    override fun getLayoutResourceId(): Int = R.layout.com_activity_app_payment

    override fun initView() {
        cbWechatPay.isChecked = true

        paymentNow.text = String.format("确认支付￥%s", APIDataHelper.generatePriceString(payMoney))
        if(payMoney == 0.0){
            paymentNow.isEnabled = false
        }
    }

    override fun initListener() {
        ll_wechat.onClick {
            cbWechatPay.performClick()
        }
        ll_alipay.onClick {
            cbAliPay.performClick()
        }
        cbWechatPay.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked) {
                cbAliPay.isChecked = false

                prePayType = AppPayType.WeChat
            } else {
                prePayType = null
            }
        }
        cbAliPay.setOnCheckedChangeListener { buttonView, isChecked ->
            if (isChecked) {
                cbWechatPay.isChecked = false

                prePayType = AppPayType.AliPay
            } else {
                prePayType = null
            }
        }

        paymentNow.onClick {
            if (prePayType == null) {
                ToastHelper.toastMessage("请选择支付方式！")
                return@onClick
            }

            when (prePayType) {
                AppPayType.AliPay -> {
                    doAliPay()
                }
                AppPayType.WeChat -> {
                    doWeChatPay()
                }
            }
        }
    }

    override fun initData() {
    }

    open fun doWalletPay(payPassword : String){
    }

    open fun doWeChatPay(){

    }

    open fun doAliPay(){
    }
}